package sqlite

import (
	"gorm.io/gorm"
	"time"
)

type OCHeartBeat struct {
	Num      int
	DeviceID int
	Value    int
}

// GPS 坐标（完全不动）
type GPS struct {
	Lat float32
	Lon float32
	Alt float32
}

type OCMessage struct {
	ID        uint      `gorm:"primaryKey;autoIncrement"`
	CreatedAt time.Time `gorm:"index"`

	Device    uint32 `gorm:"column:device;index"`
	Serial    string `gorm:"column:serial;size:64"`
	ModelID   uint32 `gorm:"column:model_id"`
	ModelName string `gorm:"column:model_name;size:128"`
	UUID      string `gorm:"column:uuid;size:64;index"`

	// ---------- Drone GPS ----------
	DroneLat float32 `gorm:"column:drone_lat"`
	DroneLon float32 `gorm:"column:drone_lon"`
	DroneAlt float32 `gorm:"column:drone_alt"`

	// ---------- Home GPS ----------
	HomeLat float32 `gorm:"column:home_lat"`
	HomeLon float32 `gorm:"column:home_lon"`
	HomeAlt float32 `gorm:"column:home_alt"`

	// ---------- Pilot GPS ----------
	PilotLat float32 `gorm:"column:pilot_lat"`
	PilotLon float32 `gorm:"column:pilot_lon"`
	PilotAlt float32 `gorm:"column:pilot_alt"`

	Height   float32 `gorm:"column:height"`
	Altitude float32 `gorm:"column:altitude"`
	EastV    float32 `gorm:"column:east_v"`
	NorthV   float32 `gorm:"column:north_v"`
	UpV      float32 `gorm:"column:up_v"`
	Freq     float32 `gorm:"column:freq"`
	Rssi     int32   `gorm:"column:rssi"`
	Distance float32 `gorm:"column:distance"`
}

type SignalMessage struct {
	ID        uint      `gorm:"primaryKey;autoIncrement"`
	CreatedAt time.Time `gorm:"index"`

	Device uint32  `gorm:"column:device;index"`
	Model  string  `gorm:"column:model;size:128"`
	Freq   float32 `gorm:"column:freq"`
	Rssi   float32 `gorm:"column:rssi"`
	Seq    uint32  `gorm:"column:seq"`
	GPIO   uint32  `gorm:"column:gpio"`
}

func (m *OCMessage) BeforeCreate(tx *gorm.DB) error {
	m.CreatedAt = time.Now()
	return nil
}

func (m *SignalMessage) BeforeCreate(tx *gorm.DB) error {
	m.CreatedAt = time.Now()
	return nil
}

// 表名
func (OCMessage) TableName() string     { return "oc_messages" }
func (SignalMessage) TableName() string { return "signal_messages" }
